package com.example.demo01.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 获取项目根目录
        String projectPath = System.getProperty("user.dir");
        // 头像存储的完整路径
        String avatarDir = projectPath + File.separator + "file/avatar";
        
        // 添加资源映射
        registry.addResourceHandler("/avatar/**")
                .addResourceLocations("file:" + avatarDir + File.separator);
    }
}